package com.wangwenjun.mocktio;

import com.wangwenjun.mocktio.Account;
import com.wangwenjun.mocktio.AccountDao;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 叶子
 * @date: 2022/05/12 23:28
 **/
public class AccountLoginController {

    private final AccountDao accountDao;

    public AccountLoginController(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public String login(HttpServletRequest request){
        final String username = request.getParameter("username");
        final String password = request.getParameter("password");
        try {
            Account account = accountDao.findAccount(username, password);
            if (account ==null){
                return "/login";
            }else {
                return "/index";
            }
        } catch (Exception e) {
           return "/505";
        }
    }
}